version: '3.9'

services:
  shard1:
    image: spqr-shard-image
    environment:
      - POSTGRES_USER=regress
      - POSTGRES_DB=regress
    ports:
      - "5500:6432"
    hostname: spqr_shard_1
    container_name: spqr_shard_1
    healthcheck:
      test: psql -h spqr_shard_1 -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50
  shard2:
    image: spqr-shard-image
    environment:
      - POSTGRES_USER=regress
      - POSTGRES_DB=regress
    ports:
      - "5501:6432"
    hostname: spqr_shard_2
    container_name: spqr_shard_2
    healthcheck:
      test: psql -h spqr_shard_2 -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50

  router:
    build:
      dockerfile: ./docker/router/Dockerfile
      context: ../../
    ports:
      - "6432:6432"
      - "7432:7432"
      - "7012:7002"
    environment:
      - ROUTER_CONFIG=${ROUTER_CONFIG}
      - ROUTER_LOG='router1.log'
      - 'ROUTER_HOST=host: ''regress_router'''
      - COORDINATOR_CONFIG=${COORDINATOR_CONFIG}
    hostname: regress_router
    container_name: regress_router
    depends_on:
      shard1:
        condition: service_healthy
      shard2:
        condition: service_healthy
    healthcheck:
      test: psql -h regress_router -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50

  router2:
    build:
      dockerfile: ./docker/router/Dockerfile
      context: ../../
    ports:
      - "6433:6432"
      - "7433:7432"
      - "7022:7002"
    environment:
      - ROUTER_CONFIG=${ROUTER_CONFIG}
      - ROUTER_LOG='router2.log'
      - 'ROUTER_HOST=host: ''regress_router_2'''
      - COORDINATOR_CONFIG=${COORDINATOR_CONFIG_2}
    hostname: regress_router_2
    container_name: regress_router_2
    depends_on:
      shard1:
        condition: service_healthy
      shard2:
        condition: service_healthy
    healthcheck:
      test: psql -h regress_router_2 -p 6432 -U regress -d regress
      interval: 10s
      timeout: 3s
      retries: 50

  coordinator:
    build:
      dockerfile: ./docker/coordinator/Dockerfile
      context: ../../
    ports:
      - "7002:7002"
      - "7003:7003"
    environment:
      - COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator.yaml
    hostname: regress_coordinator
    container_name: regress_coordinator
    depends_on:
      - "router"
      - "router2"
      - "qdb01"

  coordinator2:
    build:
      dockerfile: ./docker/coordinator/Dockerfile
      context: ../../
    ports:
      - "7032:7002"
      - "7033:7003"
    environment:
      - COORDINATOR_CONFIG=/spqr/test/feature/conf/coordinator2.yaml
    hostname: regress_coordinator_2
    container_name: regress_coordinator_2
    depends_on:
      - "router"
      - "router2"
      - "qdb01"

  qdb01:
    image: 'bitnami/etcd:latest'
    hostname: regress_qdb_0_1
    container_name: regress_qdb_0_1
    environment:
      ALLOW_NONE_AUTHENTICATION: "yes"
      ETCD_LOG_LEVEL: "debug"
    ports:
      - "2379:2379"

#networks:
#  mysync_net:
#    driver: bridge
#    ipam:
#      driver: default
#      config:
#       - subnet: 192.168.233.0/24
#         gateway: 192.168.233.1
